package THREAD.homework;
    /*
       3)、模拟三个老师同时分发80份学习笔记，
       每个老师相当于一个线程。
     */
public class homework03 implements Runnable {
        int sum = 80;
        int i = 1;
        @Override
        public void run() {

            while (sum>0){
                provide();
                if (i==80){
                    break;
                }
            }
        }
        public synchronized void provide(){
            String name = Thread.currentThread().getName();
            System.out.println(name+"正在发第"+i+"个本子");
            sum--;
            i++;
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        public static void main(String[] args) {
            homework03 hh = new homework03();
            Thread t1 = new Thread(hh,"张老师");
            Thread t2 = new Thread(hh,"李老师");
            Thread t3 = new Thread(hh,"操老师");
            t1.start();
            t2.start();
            t3.start();
        }
    }
